<?php
	/**
	 * Application level Controller
	 *
	 * This file is application-wide controller file. You can put all
	 * application-wide controller-related methods here.
	 *
	 * PHP 5
	 *
	 * @link          http://cakephp.org CakePHP(tm) Project
	 * @package       app.Controller
	 * @since         CakePHP(tm) v 0.2.9
	 */

	App::uses('Controller', 'Controller');

	/**
	 * Application Controller
	 *
	 * Add your application-wide methods in the class below, your controllers
	 * will inherit them.
	 *
	 * @package        app.Controller
	 * @link        http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
	 */
	class AppController extends Controller
	{
		var $components = array('Session','RequestHandler', 'Usermgmt.UserAuth','FilterResults.Filter' => array(
        'auto' => array(
            'paginate' => false,
            'explode'  => true,  // recomendado
        ),
        'explode' => array(
            'character'   => ' ',
            'concatenate' => 'AND',
        )
    ));
		var $helpers = array('Form', 'Html','Msg', 'Session', 'Js', 'Usermgmt.UserAuth','FilterResults.Search');

		function beforeFilter(){
			$this->userAuth();
		}
		private function userAuth(){
			$this->UserAuth->beforeFilter($this);
		}

		/**
		 * showMessage method
		 * Formata o metodo setFlash de modo mais facil
		 * @var $message String;
		 * @var $other Array('type','close','title');
		 */
		protected function showMessage($message,$option =array())
		{
			$msg = '';
			if(!empty($message)){
				$btnCloseMsg = '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>';
				$msg = $this->Session->setFlash($btnCloseMsg.$message,'default',array('class'=>'alert alert-warning'));
				if((is_array($option)) && (count($option) > 0)){
					$title	= isset($option['title']) && !empty($option['title'])? "<strong>".$option['title']."</strong>&nbsp;":'';
					$type	= isset($option['type']) && !empty($option['type'])? $option['type']: 'warning';
					$close	= isset($option['close']) && $option['close']==false? '':$btnCloseMsg;
					$message = $close.$title.$message;
					$msg = $this->Session->setFlash($message,'default',array('class'=>'alert alert-'.$type,'escape'=>false));
				}
			}
			return $msg;
		}

		protected function tokenUser(){
			$constant = "1s5d258ewr58523wfdhsk1ghkh54521gfsd89hgh";
			$pass_name = "orçamento";
			$user_id = $this->Session->read('UserAuth.User.id');
			$tokenUser = sha1($constant.$user_id.$pass_name);
			return $tokenUser;
		}
	}
